package com.midea.ai.air.ui.more;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.midea.ai.air.R;
import com.midea.ai.air.common.BaseActivity;
import com.midea.ai.air.common.KJScrollView;
import com.midea.ai.air.ui.more.adapter.MoreSettingBrainpowerAdapter;
import com.midea.ai.air.view.MyTitleBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hww on 2016/3/24.
 * 更多-智能联动
 */
public class MoreSettingBrainpower extends BaseActivity implements View.OnClickListener {

    private TextView actionbar_left_tv;
    private ListView listView;
    private RelativeLayout new_linkage;
    private MoreSettingBrainpowerAdapter adapter;
    private KJScrollView mScrollView, mScrollView_not_data;
    public static String BRAINPOWER = "brainpower";
    public static String BRAINPOWER_NEW = "brainpower_new";
    public static String BRAINPOWER_MODIFICATION = "brainpower_modification";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moresettingbrainpower);

        init();
    }

    MyTitleBar myTitleBar;

    private void init() {
        myTitleBar = new MyTitleBar(this);
        myTitleBar.setActionBar_center(R.string.more_setting_brainpower);
        myTitleBar.setActioBar_left(true, R.drawable.register_titler_left, R.string.nav_bar_more);
        myTitleBar.setActionBar_right_iv(true, R.drawable.more_setting_branpower_right);

        actionbar_left_tv = (TextView) findViewById(R.id.actionbar_tv_left);
        actionbar_left_tv.setTextColor(getResources().getColor(R.color.electric_histogram));
        new_linkage = (RelativeLayout) findViewById(R.id.more_setting_brainpower_new_linkage);
        listView = (ListView) findViewById(R.id.more_setting_brainpower_listview);
        mScrollView = (KJScrollView) findViewById(R.id.more_setting_brainpower_scrollview_data);
        mScrollView_not_data = (KJScrollView) findViewById(R.id.more_setting_brainpower_scrollview_not_data);
        new_linkage.setOnClickListener(this);

        //获取(1-10)的随机数
        int random = 1 + (int) (Math.random() * 10);

        //如果随机数大于5，则有数据显示，否则无数据显示
        if (random > 5) {
            mScrollView.setVisibility(View.VISIBLE);
            mScrollView_not_data.setVisibility(View.GONE);
            getData();
            adapter = new MoreSettingBrainpowerAdapter(MoreSettingBrainpower.this, data);
            listView.setAdapter(adapter);
        } else {
            mScrollView.setVisibility(View.GONE);
            mScrollView_not_data.setVisibility(View.VISIBLE);
        }

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(MoreSettingBrainpower.BRAINPOWER_MODIFICATION);
            }
        });

    }


    private void startActivity(String Tag) {
        Intent intent = new Intent(MoreSettingBrainpower.this, MoreSettingNewBrainpower.class);
        Bundle bundle = new Bundle();
        bundle.putString(MoreSettingBrainpower.BRAINPOWER, Tag);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    private List<brainpower_context> data = new ArrayList<brainpower_context>();

    private void getData() {
        brainpower_context bc1 = new brainpower_context();
        bc1.setTv("我的家室外PM2.5高于100  打开净化器");
        bc1.setState(true);
        bc1.setGetDrawable_on_off(R.drawable.more_setting_location_bt_on);
        bc1.setDrawable_one(R.drawable.more_setting_branpower_31);
        bc1.setDrawable_two(R.drawable.more_setting_branpower_big_04);
        bc1.setDrawable_three(R.drawable.more_setting_branpower_big_10);
        data.add(bc1);
        brainpower_context bc2 = new brainpower_context();
        bc2.setTv("客厅室内唯独高于30℃  打开舒适模式");
        bc2.setState(false);
        bc2.setGetDrawable_on_off(R.drawable.more_setting_location_bt_off);
        bc2.setDrawable_one(R.drawable.more_setting_branpower_31);
        bc2.setDrawable_two(R.drawable.more_setting_branpower_big_02);
        bc2.setDrawable_three(R.drawable.more_setting_branpower_big_08);
        data.add(bc2);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.actionbar_left_relativeLayout:

                finish();
                break;
            case R.id.actionbar_iv_right:
                startActivity(new Intent(this, MoreSettingBrainpowerLogging.class));
                break;
            case R.id.more_setting_brainpower_new_linkage:
                //新建联动
//                startActivity(new Intent(MoreSettingBrainpower.this, MoreSettingNewBrainpower.class));
                startActivity(MoreSettingBrainpower.BRAINPOWER_NEW);
                break;
        }
    }

    public class brainpower_context {
        private String tv;
        private boolean state;
        private int drawable_one, drawable_two, drawable_three;
        private int getDrawable_on_off;

        public String getTv() {
            return tv;
        }

        public void setTv(String tv) {
            this.tv = tv;
        }

        public boolean getState() {
            return state;
        }

        public void setState(boolean state) {
            this.state = state;
        }

        public int getDrawable_two() {
            return drawable_two;
        }

        public void setDrawable_two(int drawable_two) {
            this.drawable_two = drawable_two;
        }

        public int getDrawable_one() {

            return drawable_one;
        }

        public void setDrawable_one(int drawable_one) {
            this.drawable_one = drawable_one;
        }

        public int getGetDrawable_on_off() {
            return getDrawable_on_off;
        }

        public void setGetDrawable_on_off(int getDrawable_on_off) {
            this.getDrawable_on_off = getDrawable_on_off;
        }

        public int getDrawable_three() {

            return drawable_three;
        }

        public void setDrawable_three(int drawable_three) {
            this.drawable_three = drawable_three;
        }
    }

}
